<!--
关注
 -->
<template>
  <div>
    <noMore v-if="taskdata.length == 0"></noMore>

    <div class="task" v-for="(item, index) in taskdata" :key="index">
      <div class="taskBox">
        <div class="taskLeft">
          <div class="taskBoxTitle">
            <div class="headText">
              <div class="headName">{{ item.taskname }}</div>
              <div class="headTell">
                <div>任务完成可得:</div>
                <div>+ {{ item.integral }}</div>
              </div>
              <div class="headAboat">
                <div class="tasker">{{ item.isok }} / {{ item.frequency }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="taskRight">
          <div v-if="item.isok == item.frequency">
            <img class="taskimg" src="../../../assets/taskOk.png" />
            <div class="tasktxt">已完成</div>
          </div>
          <div v-else>
            <img class="taskimg" src="../../../assets/taskunok.png" />
            <div>待完成</div>
          </div>
        </div>
      </div>

      <el-divider></el-divider>
    </div>
    <!-- <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
    >
    </el-pagination> -->
  </div>
</template>

<script>
import noMore from "../../../components/noMore";
import { get_task } from "../../../api/task";
import { get_completeTask } from "../../../api/completeTask";
export default {
  name: "task",
  data() {
    return {
      currentPage4: 4,
      taskdata: [],
      isok: false
    };
  },
  watch: {
    $route(newRouter) {
      //监听路由是否变化
      if (newRouter.path == "/personalCenter") {
        this.getdata();
      }
    }
  },
  components: {
    noMore
  },
  created() {
    this.getdata();
  },
  methods: {
    async getdata() {
      var taskdata = await get_task({ query: {} });
      console.log("任务列表", taskdata);
      this.taskdata = taskdata.data;
      let startTime = new Date(
        new Date(new Date().getTime()).setHours(0, 0, 0, 0)
      ); // 当天0点
      let endTime = new Date(
        new Date(new Date().getTime()).setHours(23, 59, 59, 999)
      );
      console.log(startTime, endTime, "时间范围");
      //判断是否有
      for (let index = 0; index < this.taskdata.length; index++) {
        const element = this.taskdata[index];
        console.log(element);
        var completeTaskdata = await get_completeTask({
          query: {
            userid: this.$store.getters.userInfo._id,
            taskid: element._id,
            $and: [
              { complete_time: { $gt: startTime } },
              { complete_time: { $lt: endTime } }
            ]
          }
        });
        console.log(this.taskdata[index], "isok", completeTaskdata.data);
        this.$set(this.taskdata[index], "isok", completeTaskdata.data.length);
      }
      if (this.$store.getters.userInfo) {
        this.userInfo = this.$store.getters.userInfo;
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
};
</script>

<style lang="scss" scoped>
.task {
  .taskBox {
    height: 100px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    .taskLeft {
      width: 80%;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .taskBoxTitle {
        display: flex;
        align-items: center;
        .headimg {
          height: 60px;
          width: 60px;
          border-radius: 50%;
          border: solid 1px #808080;
        }
        .headText {
          margin: 0 0 0 24px;
          display: flex;
          flex-direction: column;
          .headName {
            font-size: 20px;
            margin: 10px 0;
            font-weight: 550;
          }
          .headAboat {
            font-size: 14px;
            margin: 4px 0;
            color: #808080;
            color: #6c6c6c;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2; /* 可以显示的行数，超出部分用...表示*/
            -webkit-box-orient: vertical;
          }
          .headTell {
            display: flex;
            font-size: 14px;
            width: 160px;
            .tasker {
              margin-left: 10px;
              font-weight: 550;
            }
          }
        }
      }
    }
    .taskRight {
      display: flex;
      align-items: center;
      padding: 30px 0 0 0;
      .taskimg {
        width: 50px;
        height: 50px;
      }
      .tasktxt {
        color: green;
      }
      .taskBtn {
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        background-color: #8590a6;
        border: 1px solid #dcdfe6;
        color: #ffffff;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: 0;
        margin: 0;
        transition: 0.1s;
        font-weight: 500;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px;
      }
      .taskBtns {
        background-color: #67c23a;
        border-color: #67c23a;
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        border: 1px solid #dcdfe6;
        color: #ffffff;
        -webkit-appearance: none;
        text-align: center;
        box-sizing: border-box;
        outline: 0;
        margin: 0;
        transition: 0.1s;
        font-weight: 500;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: 4px;
      }
    }
  }
}
</style>
